package com.example.pc.greenplants;


import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;

import java.util.List;

public class PlantAdapter extends RecyclerView.Adapter<PlantAdapter.ViewHolder> {


    private List<Plant> mPlantList;



    static  class ViewHolder extends RecyclerView.ViewHolder{
        View plantView;
        ImageButton plantImage;
        TextView plantName;

        public ViewHolder(View itemView) {
            super(itemView);
            plantView = itemView;
            plantImage = itemView.findViewById(R.id.plant_image);
            plantName = itemView.findViewById(R.id.plant_name);
        }
    }

    public PlantAdapter(List<Plant> plantList){
        mPlantList = plantList;
        //
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.plant_item,parent,false);
        final ViewHolder holder = new ViewHolder(view);
        /*
        holder.plantView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = holder.getAdapterPosition();
                Plant plant = mPlantList.get(position);
                Toast.makeText(v.getContext(),"you "+ position,Toast.LENGTH_SHORT).show();
            }
        });
*/
            holder.plantImage.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = holder.getAdapterPosition();
                    Plant plant = mPlantList.get(position);

                    Intent intent;
                    switch (position){
                        case 0:
                           intent = new Intent(v.getContext(), DingXiangActivity.class);
                           v.getContext().startActivity(intent);
                           break;
                        case 1:
                            intent = new Intent(v.getContext(), GuiBeizhuActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 2:
                            intent = new Intent(v.getContext(),LanPenHuaActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 3:
                            intent = new Intent(v.getContext(),QingYebiyuActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 4:
                            intent = new Intent(v.getContext(), SiYeCaoActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 5:
                            intent = new Intent(v.getContext(),XiaXuepianlianActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 6:
                            intent = new Intent(v.getContext(), YuLuActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 7:
                            intent = new Intent(v.getContext(), BaiHeYuActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 8:
                            intent = new Intent(v.getContext(), ShengshihuaActivity.class);
                            v.getContext().startActivity(intent);
                            break;
                        case 9:
                            intent = new Intent(v.getContext(), DiaolanActivity.class);
                            v.getContext().startActivity(intent);
                            break;

                           default:
                               break;

                    }
                }
        });

            return holder;
    }


    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        Plant plant = mPlantList.get(i);
        viewHolder.plantName.setText(plant.getName());
        viewHolder.plantImage.setImageResource(plant.getImageId());

    }

    @Override
    public int getItemCount() {
        return mPlantList.size();
    }


}
